<!DOCTYPE html>
<html lang="zh-CN">
<head>
<!--  <base href="/Cloud/">-->
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>登录 - 云文档平台</title>
  <link rel="stylesheet" href="static/css/bootstrap.min.css">
  <link rel="stylesheet" href="static/css/auth.css">
  <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<div class="auth-container">
  <div class="card">
    <div class="card-header">
      <h4>用户登录</h4>
    </div>
    <div class="card-body">
      <form id="loginForm">
        <div class="form-group">
          <label for="username">用户名</label>
          <input type="text" class="form-control" id="username"
                 placeholder="请输入用户名" required>
        </div>
        <div class="form-group">
          <label for="password">密码</label>
          <input type="password" class="form-control" id="password"
                 placeholder="请输入密码" required>
        </div>
        <div class="form-group captcha-group">
          <label for="regCaptcha">图形验证码</label>
          <div class="input-group">
            <input type="text" class="form-control" id="regCaptcha"
                   placeholder="请输入验证码" required>
            <div class="input-group-append">
              <img id="regCaptchaImg" src="" alt="验证码"
                   onclick="refreshRegCaptcha()">
              <input type="hidden" id="regCaptchaToken">
            </div>
          </div>
        </div>
        <button type="submit" class="btn btn-primary btn-block">登录</button>
      </form>
      <div class="auth-links">
        <a href="/Cloud/register.html">注册账号</a>
        <a href="/Cloud/forgot-password.html" id="forgotPassword">忘记密码？</a>
      </div>
    </div>
  </div>
</div>
<script src="static/js/auth.js"></script>
<script>
  $(document).ready(function() {
    refreshRegCaptcha();
    $("#regUsername").on("input", function() {
      checkUsernameAvailable($(this).val());
    });
    $("#loginForm").submit(function(e) {
      e.preventDefault();
      login();
    });
  });

  function refreshRegCaptcha() {
    $.get("/Cloud/captcha", function(res) {
      $("#regCaptchaImg").attr("src", res.image);
      $("#regCaptchaToken").val(res.token);
    });
  }
</script>
</body>
</html>